package cn.zbmao.web.dao;

import cn.zbmao.web.bean.Constants;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import java.util.List;

/**
 * Created by 愤怒的番茄 on 2014/9/15.
 */
public class LocationDao {

    /**
     * 获取地市信息列表，用于搜索选择地市区域选择框
     * @return
     */
    public List<Record> getLocationList(int id){
        return Db.find("SELECT * FROM " + Constants.DISTRICT + " WHERE  and parentid=?", id);
                                     //gd
    }

    /**
     * 通过上级Id查询数据
     * @param id
     * @return
     */
    public List<Record> getLocationList1(int id){
        return Db.find("SELECT * FROM " + Constants.DISTRICT + " WHERE  parentid=?", id);
        //gd
    }

    /**
     *查询层级为1的所有 地域
     * @return
     */
    public List<Record> getLocationList(){
        return Db.find("select * from "+Constants.DISTRICT+" where parentid=0  and suffix='市' order by initial");
    }
    public List<Record> getLocationList_u(){
        return Db.find("select * from "+Constants.DISTRICT+" where parentid=0  and suffix!='市' order by initial");
    }

    /**
     * 查询用户的层级
     * @param code
     * @return
     */
    public Record findLevel(int code){
        return Db.findFirst("select * from "+Constants.DISTRICT+" where code=?",code);
    }
    public Record findById(int id){
        return Db.findFirst("select * from "+Constants.DISTRICT+" where id=?",id);
    }



}
